package com.aruba.thymeleaf.service.impl;

import com.aruba.thymeleaf.bean.Emp;
import com.aruba.thymeleaf.mapper.EmpMapper;
import com.aruba.thymeleaf.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public List<Emp> findAllEmp() {
        return empMapper.findAllEmp();
    }

    @Override
    public List<Emp> findEmpByPage(Integer pageSize, Integer pageNum) {
        Page<Emp> page = PageHelper.startPage(pageNum, pageSize);
        List<Emp> list = empMapper.findAllEmp();
        // Page对象获取
        System.out.println("当前页:" + page.getPageNum());
        System.out.println("总页数" + page.getPages());
        System.out.println("页大小:" + page.getPageSize());
        System.out.println("总记录数:" + page.getTotal());
        System.out.println("当前页数据" + page.getResult());

        // PageInfo对象获取
        PageInfo<Emp> empPageInfo = new PageInfo<>(list);
        System.out.println("当前页:" + empPageInfo.getPageNum());
        System.out.println("总页数" + empPageInfo.getPages());
        System.out.println("页大小:" + empPageInfo.getPageSize());
        System.out.println("总记录数:" + empPageInfo.getTotal());
        System.out.println("当前页数据" + empPageInfo.getList());

        return list;
    }

    @Override
    public boolean deleteEmpByNoAndName(Integer empno, String ename) {
        return empMapper.deleteEmp(empno, ename) > 0;
    }

}
